// <copyright file="SimpleCamera.cs" company="SpaceRock Team Members">
// Project: SpaceRock
// File: SimpleCamera.cs (4,67 KB, 161 lines)
// Creation date: 2010-05-28 15:10
// Last modified: 2010-07-29 12:53
// </copyright>

#region Using directives
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion

namespace SpaceRockTeam.SpaceRock.Components
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class SimpleCamera : GameComponent
    {
        /// <summary>
        /// View field
        /// </summary>
        private float viewField;

        /// <summary>
        /// View perspective
        /// </summary>
        private float viewPerspective;

        /// <summary>
        /// Near plane
        /// </summary>
        private float nearPlane;

        /// <summary>
        /// Far plane
        /// </summary>
        private float farPlane;

        /// <summary>
        /// Position
        /// </summary>
        public Vector3 Position { get; set; }

        /// <summary>
        /// Target
        /// </summary>
        public Vector3 Target { get; set; }

        /// <summary>
        /// Projection
        /// </summary>
        public Matrix Projection
        {
            get
            {
                return Matrix.CreatePerspectiveFieldOfView(viewField, viewPerspective, nearPlane, farPlane);
            }
        } // Projection

        /// <summary>
        /// View
        /// </summary>
        public Matrix View
        {
            get
            {
                return Matrix.CreateLookAt(Position, Target, Vector3.Up);
            }
        } // View

        /// <summary>
        /// Set projection
        /// </summary>
        public void SetProjection(float viewField, float viewPerspective, float nearPlane, float farPlane)
        {
            this.viewField = viewField;
            this.viewPerspective = viewPerspective;
            this.nearPlane = nearPlane;
            this.farPlane = farPlane;
        } // SetProjection

        /// <summary>
        /// Create simple camera
        /// </summary>
        public SimpleCamera(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
        } // SimpleCamera

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Q))
            {
                float update = gameTime.ElapsedGameTime.Milliseconds * 0.1f;
                Position += new Vector3(update, 0.0f, 0.0f);
            }

            if (keyboardState.IsKeyDown(Keys.W))
            {
                float update = gameTime.ElapsedGameTime.Milliseconds * 0.1f;
                Position -= new Vector3(update, 0.0f, 0.0f);
            }

            if (keyboardState.IsKeyDown(Keys.A))
            {
                float update = gameTime.ElapsedGameTime.Milliseconds * 0.1f;
                Position += new Vector3(0.0f, update, 0.0f);
            }

            if (keyboardState.IsKeyDown(Keys.S))
            {
                float update = gameTime.ElapsedGameTime.Milliseconds * 0.1f;
                Position -= new Vector3(0.0f, update, 0.0f);
            }

            if (keyboardState.IsKeyDown(Keys.Z))
            {
                float update = gameTime.ElapsedGameTime.Milliseconds * 0.1f;
                Position += new Vector3(0.0f, 0.0f, update);
            }

            if (keyboardState.IsKeyDown(Keys.X))
            {
                float update = gameTime.ElapsedGameTime.Milliseconds * 0.1f;
                Position -= new Vector3(0.0f, 0.0f, update);
            }

            base.Update(gameTime);
        } // Update
    } // class SimpleCamera
} // namespace SpaceRockTeam.SpaceRock.Components
